﻿/**
 * @file file.h
 * @date 23.5.3
 * @author yrz
 * @brief 文件相关数据结构
 * @version 0.1
 * @status Stable
**/

struct file {
	enum { FD_NONE, FD_PIPE, FD_INODE, FD_DEVICE } type;
	int ref;			// 引用数
	char readable;
	char writable;
	struct pipe* pipe; // FD_PIPE
	struct inode* ip;  // FD_INODE 和 FD_DEVICE
	uint off;          // FD_INODE
	short major;       // FD_DEVICE
};

struct devsw {
	int (*read)(int, uint64, int);
	int (*write)(int, uint64, int);
};

extern struct devsw devsw[];

#define CONSOLE 1

#define major(dev)  ((dev) >> 16 & 0xFFFF)
#define minor(dev)  ((dev) & 0xFFFF)
#define	mkdev(m,n)  ((uint)((m)<<16| (n)))

struct inode {
	uint dev;           // 设备号
	uint inum;          // 索引节点号
	int ref;            // 引用数
	//struct sleeplock lock; // protects everything below here
	int valid;          // 是否已从磁盘读取

	short type;         // 类型
	short major;
	short minor;
	short nlink;
	uint size;
	uint addrs[NDIRECT + 1];
};